package tcc.model.graph;

/**
 * Represents a edge in a graph
 * @author Gabriel Pacheco
 *
 */
public class Edge {
	private double distance = 0;
	private double pheromone = 1;
	private final double evaporationPheromoneTax = 0.30;
	
	private Vertex beginVertex; 
	private Vertex endVertex;
	
	/**
	 * Create an edge between v1 and v2
	 * @param v1 start Vertex
	 * @param v2 final Vertex
	 * @param dist distance beetween the vertex
	 * 
	 */
	public Edge (Vertex v1, Vertex v2, double dist) { //FIXME - TALVEZ haja a necessidade de rever
			this.beginVertex = v1;
			this.endVertex = v2;
			this.distance = dist;
			v1.addEdges(this);
			v1.setNEdges(1);
			v2.setNEdges(1);
	}
	
	public double getDistance() {
		return distance;
	}

	public double getPheromone() {
		return pheromone;
	}

	/**
	 * 
	 * @param pheromone New quantity of pheromone on the edge
	 */
	public void setPheromone(int pheromone) { //FIXME
		if(pheromone > 0) {
			this.pheromone = pheromone;
		}else {
			this.pheromone = 0;
		}		
	}
	
	/**
	 * refresh the pheromone on the edge and ensure the edge don't has phromone less then 1
	 * @param increasePheromone quantity of pheromone to incress on edge
	 */
	public void increasePheromone(double increasePheromone) {
		  this.pheromone = (1-this.evaporationPheromoneTax)*this.pheromone + increasePheromone;
		  if (this.pheromone < 1 ) {
			  this.pheromone = 1;
		  }
	}
	
	//DESUSO
	/**
	 * Release the pheromone in the edge 
	 */
	/*public void evaporatePheromone() {
		this.pheromone = (1-this.evaporationPheromoneTax)*this.pheromone;
	}*/

	public Vertex getBeginVertex () {
		return this.beginVertex;
	}
	
	public Vertex getEndVertex () {
		return this.endVertex;
	}
	
	
	/**
	 * Verify if two edges are equals 
	 * @param ed a Edge to compare
	 * @return true if equals
	 */
	public Boolean equals (Edge ed) {
		if (ed instanceof Edge &&
			(ed.getBeginVertex().equals(this.getBeginVertex() ) &&
			 ed.getEndVertex().equals(this.getEndVertex())) || 
			(ed.getBeginVertex().equals(this.getEndVertex() ) &&
			ed.getEndVertex().equals(this.getBeginVertex()) )
			) {
				return true;			
		}
		
		return false;
	}
}